package com.wintrue.ffxs.ui.home;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.wintrue.ffxs.R;
import com.wintrue.ffxs.ui.home.adapter.XlvAdapter;
import com.wintrue.ffxs.widget.xlistview.XListView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by wenjie on 2017/8/16.
 */

public class HomeFragment extends Fragment {

    View view ,views;
    XListView xlv;

    ArrayList<Map<String,Object>>  list = new ArrayList<Map<String,Object>>();
    int page=0;
    XlvAdapter adapter;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if(view == null)
        {
            view = inflater.inflate(R.layout.fragment_home,container,false);
        }
        xlv= (XListView) view.findViewById(R.id.xlv);
        getData();


       views=LayoutInflater.from(getActivity()).inflate(R.layout.home_xlistview_header,null);

        adapter=new XlvAdapter(list,getContext());
       xlv.setAdapter(adapter);
        xlv.setXListViewListener(new XListView.IXListViewListener() {
            @Override
            public void onRefresh() {
                list.clear();
                page=0;
                getData();
                adapter.notifyDataSetChanged();
                //停止刷新
                xlv.stopRefresh();
                //设置停止刷新时间
                xlv.setRefreshTime("刚刚");
            }

            @Override
            public void onLoadMore() {
                if(list!=null){
                    page++;
                }
                getData();
                adapter.notifyDataSetChanged();
                //停止加载更多
                xlv.stopLoadMore();
            }
        });

        return view;
    }



    private void getData(){

    }

}
